#include "stdafx.h"
#include "RandString.h"

char* rand_string( unsigned len )
{
	char* retval = new char[len+1];
	char* buf = retval;
	while(len--) 
		*(buf++) = char( (unsigned long)rand() * (END_C-START_C) / RAND_MAX + START_C);
	*buf = 0;
	return retval;
}

char** rand_string_list( unsigned num, unsigned minlen, unsigned maxlen )
{
	char** strlist = new char*[num+1];
	char** lst = strlist;
	maxlen-=minlen;
	while(num--) 
		*(lst++) = rand_string( ((unsigned long)rand() * maxlen / RAND_MAX) + minlen );
	*lst = 0;
	return strlist;
}

void del_rand_list( char** list )
{
	for( char** l = list; *l; )
		delete[] *(l++);
	delete[] list;
}

RandString::RandString( int length ) : str(length,' ')
{
	for( int i=0;i<length;i++ )
		str[i] = char( (unsigned long)rand() * (endchar-startchar) / RAND_MAX + startchar);
}

RandStringList::RandStringList( int number, int minlength, int maxlength )
{
	for( int i=0;i<number;i++)
	{
		int length = ((unsigned long)rand() * (maxlength-minlength) / RAND_MAX) + minlength;
		strlist.push_back( RandString(length).getString() );
	}
}
